package org.huangrui.juc.source.Interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * 中断运行中线程
 * @Author hr
 * @Create 2024-04-02 10:33
 */
public class T02_Interrupt {
    public static void main(String[] args) {
        //实例方法interrupt()仅仅是设置线程的中断状态位设置为true，不会停止线程
        Thread t1 = new Thread(() -> {
            for (int i = 1; i <= 300; i++) {
                System.out.println( "-----: "+i);
            }
            System.out.println("t1线程调用interrupt()后的的中断标识02："+Thread.currentThread().isInterrupted());
        }, "t1");
        t1.start();
        System.out.println("-----t1的默认中断标志位："+t1.isInterrupted());
        //暂停1毫秒
        try { TimeUnit.MILLISECONDS.sleep(1);} catch (InterruptedException e) {e.printStackTrace();}
        t1.interrupt();
        System.out.println("t1线程调用interrupt()后的的中断标识01："+t1.isInterrupted());
        //暂停200毫秒
        try { TimeUnit.MILLISECONDS.sleep(200);} catch (InterruptedException e) {e.printStackTrace();}
        System.out.println("t1线程调用interrupt()后的的中断标识03："+t1.isInterrupted()); //????---false中断不活动的线程不会产生任何影响。
    }
}
